package springboot_cae.serviceimpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import springboot_cae.dao.CaeDao;
import springboot_cae.entity.CaeEntity;
import springboot_cae.service.CaeService;

@Service
public class CaeServiceImpl implements CaeService{
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
	@Autowired
	private CaeDao caeDao;
	
	@Override
	//查询数据
	public List<CaeEntity> selectService() {
		return caeDao.select();
	}

	@Override
	//查询信息
	public CaeEntity selectByService(int id) {
		return caeDao.selectBy(id);
	}

	@Override
	//修改信息
	public boolean updateService(CaeEntity caeEntity) {
		boolean flag=false;
		try {
			caeDao.update(caeEntity);
			System.out.println("编辑成功！");
			System.out.println("当前时间: "+df.format(new Date()));
			flag=true;
		} catch (Exception e) {
			System.out.println("编辑失败！");
			System.out.println("当前时间: "+df.format(new Date()));
		}
		return flag;
	}

	@Override
	//增加信息
	public boolean addService(CaeEntity caeEntity) {
		boolean flag=false;
		try {
			caeDao.add(caeEntity);
			System.out.println("添加成功！");
			System.out.println("当前时间: "+df.format(new Date()));
			flag=true;
		} catch (Exception e) {
			System.out.println("添加失败！");
			System.out.println("当前时间: "+df.format(new Date()));
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	//删除信息
	public boolean deleteService(int id) {
		boolean flag=false;
		try {
			caeDao.delete(id);
			System.out.println("删除成功！");
			System.out.println("当前时间: "+df.format(new Date()));
			flag=true;
		} catch (Exception e) {
			System.out.println("删除失败！");
			System.out.println("当前时间: "+df.format(new Date()));
		}
		return flag;
	}

}